//
//  StatusTableViewCell.m
//  LiveEducation
//
//  Created by Liu,Qingcan on 2017/4/11.
//  Copyright © 2017年 Baidu. All rights reserved.
//

#import "StatusTableViewCell.h"
#import "StatusButton.h"


#define BUTTONS_NUMBER 3
#define BUTTON_HEIGHT 80
#define BUTTON_WIDTH self.frame.size.width/BUTTONS_NUMBER
#define BUTTON_Y 30


@interface StatusTableViewCell()
@property (nonatomic,strong) StatusButton *recordsButton;
@property (nonatomic,strong) StatusButton *collectionButton;
@property (nonatomic,strong) StatusButton *statusButton;
@end

@implementation StatusTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
//    [self setupSubviews];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

//- (instancetype)init{
//    
//    if (self) {
//        [self setupSubviews];
//    }
//    
//    return self;
//}
+ (instancetype)cellWithTableView:(UITableView *)tableView{
    
    static NSString *identifier = @"statusCell";
    // 1.缓存中取
    StatusTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    // 2.创建
    if (cell == nil) {
            cell = [[StatusTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
    return cell;
}



- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupSubviews];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    [self.contentView addSubview:self.recordsButton];
    [self.contentView addSubview:self.collectionButton];
    [self.contentView addSubview:self.statusButton];
    
}


- (void)setupSubviews{
    
}


- (void)buttonDidSelected:(StatusButton *)button{
    if (button) {
        [self.delegate didClickedStatusButton:button];
    }
}


#pragma mark getter
- (UIButton *)recordsButton{
    if (!_recordsButton) {
        CGRect rect = CGRectMake(0, BUTTON_Y, BUTTON_WIDTH, BUTTON_HEIGHT);
        _recordsButton = [StatusButton initButtonWithImageName:@"records" subTitle:@"观看记录" frame:rect];
        _recordsButton.tag = 0;
        [_recordsButton addTarget:self action:@selector(buttonDidSelected:) forControlEvents:UIControlEventTouchUpInside];
//        _recordsButton.frame = CGRectMake(0, BUTTON_Y, BUTTON_WIDTH, BUTTON_HEIGHT);
//        [_recordsButton setImage:[UIImage imageNamed:@"records"] forState:UIControlStateNormal];
//        [_recordsButton setTitle:@"观看记录" forState:UIControlStateNormal];
    }
    return _recordsButton;
}

- (UIButton *)collectionButton{
    if (!_collectionButton) {
        CGRect rect =  CGRectMake((self.frame.size.width/BUTTONS_NUMBER)*1, BUTTON_Y, BUTTON_WIDTH, BUTTON_HEIGHT);
        _collectionButton = [StatusButton initButtonWithImageName:@"collect"
                                                         subTitle:@"收藏记录"
                                                            frame:rect];
        _collectionButton.tag = 1;
        [_collectionButton addTarget:self action:@selector(buttonDidSelected:) forControlEvents:UIControlEventTouchUpInside];
        
        
    }
    return _collectionButton;
}

- (UIButton *)statusButton{
    if (!_statusButton) {
        CGRect rect = CGRectMake((self.frame.size.width/BUTTONS_NUMBER)*2, BUTTON_Y, BUTTON_WIDTH, BUTTON_HEIGHT);
        _statusButton = [StatusButton initButtonWithImageName:@"video"
                                                     subTitle:@"直播记录"
                                                        frame:rect];
        _statusButton.tag = 2;
        [_statusButton addTarget:self action:@selector(buttonDidSelected:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _statusButton;
}

@end
